package cn.tedu.service.adminService.mpl;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.mapper.admin.Admin_LoginMapper;
import cn.tedu.pojo.admin.dto.AdminLoginDTO;
import cn.tedu.pojo.admin.model.AdminLogin;
import cn.tedu.service.adminService.Admin_LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class Admin_LoginServicempl implements Admin_LoginService {
    @Autowired(required = false)
    private Admin_LoginMapper admin_loginMapper;

    @Override
    public JsonResult addNewAdmin(AdminLoginDTO admin_loginDTO) {
        log.debug("即将增加管理员", admin_loginDTO);
        AdminLogin admin_login = new AdminLogin();
        admin_login.setAdminName(admin_loginDTO.getAdminName());
        admin_login.setAdminPassword(admin_loginDTO.getAdminPassword());
        admin_login.setAdminStats("1");
        admin_login.setIsDelete(1);
        admin_login.setGmtCreate(LocalDateTime.now());
        admin_login.setGmtModified(LocalDateTime.now());
        admin_loginMapper.insert(admin_login);
        return JsonResult.ok("注册成功");
    }

    @Override
    public void updateByAdminname(String adminName,Long id) {
//        AdminLoginDTO admin_loginDTO = new AdminLoginDTO();
//        Long i = admin_loginDTO.getId();
//        if (i != null) {
//            System.out.println("修改失败，已存在");
//        }
//        AdminLogin admin_login = new AdminLogin();
//        admin_login.setId(admin_loginDTO.getId());
//        admin_login.setAdminName(admin_loginDTO.getAdminName());
//        admin_login.setAdminPassword(admin_loginDTO.getAdminPassword());
//        admin_login.setAdminStats(admin_loginDTO.getAdminStats());
//        admin_login.setGmtCreate(LocalDateTime.now());
//        admin_login.setGmtModified(LocalDateTime.now());
//        admin_login.setIsDelete(admin_loginDTO.getIsDelete());
        admin_loginMapper.updateByAdminname(adminName,id);
        System.out.println(adminName   +id);


    }

    public void updateByPassword(String adminPassword,Long id) {
        admin_loginMapper.updateByPassword(adminPassword,id);

    }

    public void sellAdmin(AdminLoginDTO admin_loginDTO) {

        admin_loginMapper.sellAdmin(admin_loginDTO);

    }
}